#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <rtconfig.h>
#include "stm32f4xx_hal.h"


#define SAMPLE_UART_NAME       "uart3"  /* 串口设备名称 */


void uart_send_data(void)
{
    rt_device_t uart_device;
    
    const rt_uint8_t data = 0x41; 
    
    const char *message = "hello";

    // 查找串口设备
    uart_device = rt_device_find(SAMPLE_UART_NAME);
    if (uart_device == RT_NULL)
    {
        rt_kprintf("Device %s not found!\n", SAMPLE_UART_NAME);
        return;
    }
    

    // 打开设备，如果是串口设备，一般选择读写模式
    if (rt_device_open(uart_device, RT_DEVICE_FLAG_RDWR) != RT_EOK)
    {
        rt_kprintf("Failed to open %s!\n", SAMPLE_UART_NAME);
        return;
    }
    
    
    while (1)
    {
        // rt_device_write(uart_device, 0, message, rt_strlen(message));
        rt_device_write(uart_device, 0, &data, sizeof(data));
        rt_thread_mdelay(1000);
        
    }
    

    // 关闭设备
    rt_device_close(uart_device);
}

// // MSH_CMD_EXPORT(uart_send_data, uart_send_data);



